package com.muc.view;

import com.muc.entity.CarDO;
import com.muc.handler.AddCarViewHandler;

import javax.swing.*;
import java.awt.*;

public class AddCarView extends JDialog {
    JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.CENTER,10,20));

    AddCarViewHandler addCarViewHandler;
    JLabel idLabel = new JLabel("汽车ID:",JLabel.RIGHT);
    JTextField idTxt = new JTextField();
    JLabel typeLabel = new JLabel("汽车类别:",JLabel.RIGHT);
    JTextField typeTxt = new JTextField();
    JLabel numLabel = new JLabel("车牌号:",JLabel.RIGHT);
    JTextField numTxt = new JTextField();
    JLabel statusLabel = new JLabel("汽车使用状态:",JLabel.RIGHT);
    JTextField statusTxt = new JTextField();
    JLabel dateLabel = new JLabel("汽车日期:",JLabel.RIGHT);
    JTextField dateTxt = new JTextField();
    JLabel priceLabel = new JLabel("租车价格:",JLabel.RIGHT);
    JTextField priceTxt = new JTextField();
    JLabel infoLabel = new JLabel("车辆描述信息:",JLabel.RIGHT);
    JTextField infoTxt = new JTextField();

    JButton addBtn = new JButton("添加");

    public AddCarView(MainView mainView){
        super(mainView,"添加汽车",true);
        addCarViewHandler = new AddCarViewHandler(this,mainView);
        idLabel.setPreferredSize(new Dimension(80,30));
        jPanel.add(idLabel);
        idTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(idTxt);

        typeLabel.setPreferredSize(new Dimension(80,30));
        jPanel.add(typeLabel);
        typeTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(typeTxt);
        numLabel.setPreferredSize(new Dimension(80,30));
        jPanel.add(numLabel);
        numTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(numTxt);
        statusLabel.setPreferredSize(new Dimension(80,30));
        jPanel.add(statusLabel);
        statusTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(statusTxt);
        dateLabel.setPreferredSize(new Dimension(80,30));
        jPanel.add(dateLabel);
        dateTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(dateTxt);
        priceLabel.setPreferredSize(new Dimension(80,30));
        jPanel.add(priceLabel);
        priceTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(priceTxt);
        infoLabel.setPreferredSize(new Dimension(80,30));
        jPanel.add(infoLabel);
        infoTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(infoTxt);

        addBtn.addActionListener(addCarViewHandler);//设置监听事件
        jPanel.add(addBtn);
        Container contentPane = getContentPane();
        contentPane.add(jPanel);

        setSize(350,500);

        //居中
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);//销毁当前窗体
        //大小不可改变
        setResizable(false);
        setVisible(true);
    }

    public CarDO buildCarDO(){
        CarDO carDO = new CarDO();
        carDO.setCarId(Integer.valueOf(idTxt.getText()));
        carDO.setCarType(typeTxt.getText());
        carDO.setCarNum(numTxt.getText());
        carDO.setCarStatus(statusTxt.getText());
        carDO.setCarDate(dateTxt.getText());
        carDO.setCarPrice(Double.valueOf(priceTxt.getText()));
        carDO.setCarInfo(infoTxt.getText());
        return carDO;
    }
}
